class Sync 
  RUGBY_PROJECT_URL = "http://code.google.com/p/rugby/issues/"
  
  def Sync.milestones
    milestones = []
    if ENV['ISSUE_TRACKER'] == 'trac'
      Milestone.find_all.each do |milestone|
        milestones << MilestoneStruct.new(:name => milestone.name)
      end
    end
    if ENV['ISSUE_TRACKER'] == 'google'
      gph = GoogleProjectHost.new(RUGBY_PROJECT_URL)
      milestones = gph.list_milestones
    end
    
    milestones
  end
  
  def Sync.tickets(milestone)
    tickets = []
    if ENV['ISSUE_TRACKER'] == 'trac'
      Ticket.find_all_by_milestone(milestone).each do |ticket|
        tickets << TicketStruct.new(:name => ticket.summary, :ticket_id => ticket.id, :owner=>ticket.owner, :link=>"http://here be links")
      end
    end
    if ENV['ISSUE_TRACKER'] == 'google'
      gph = GoogleProjectHost.new(RUGBY_PROJECT_URL)
      tickets = gph.list_tickets(milestone)
    end
    
    tickets
  end  
  
  def Sync.users
    owners = []
    if ENV['ISSUE_TRACKER'] == 'trac'
      TracDatabase.connection.select_values("select distinct owner from ticket").each do |owner|
        owners << UserStruct.new(:name => owner)
      end
    end
    if ENV['ISSUE_TRACKER'] == 'google'
      gph = GoogleProjectHost.new(RUGBY_PROJECT_URL)
      owners = gph.list_users
    end
    
    owners
  end  
  
end

